﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using WMSADL.SY;
using WMSAML.SY;

namespace WMSABL.SY
{
    public class TUserPermissionRelation_BLL
    {
        TUserRoleRelation_BLL bll_TUserRoleRelation = new TUserRoleRelation_BLL();
        TUserGroupRelation_BLL bll_TUserGroupRelation = new TUserGroupRelation_BLL();
        TUserPermissionRelation_DAL dal = new TUserPermissionRelation_DAL();

        /// <summary>
        /// 保存用户所属角色
        /// </summary>
        public bool SetRole(int uid, string ridstr)
        {
            if (bll_TUserRoleRelation.UpdateUserRoleRelation(uid, ridstr))
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 保存用户所属组
        /// </summary>
        public bool SetGroup(int uid, string gidstr)
        {
            if (bll_TUserGroupRelation.UpdateTUserGroupRelation(uid, gidstr))
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 保存用户权限
        /// </summary>
        public bool SetPermisissions(int uid, string strpid)
        {
            if (ExistsByID(uid))
            {
                this.Delete(uid);
            }
            if (strpid == "")
            {
                return true;
            }
            TUserPermissionRelation_Entity entity = new TUserPermissionRelation_Entity();
            entity.User_id = uid;
            entity.Permission_id = strpid;
            if (dal.Add(entity) > 0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        ///  ByUserID
        /// </summary>
        public bool Delete(int uid)
        {
            return dal.Delete(uid);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(TUserPermissionRelation_Entity entity)
        {
            return dal.Update(entity);
        }

        /// <summary>
        /// ByUID
        /// </summary>
        public bool ExistsByID(int uid)
        {
            return dal.ExistsByID(uid);
        }

        /// <summary>
        /// ByID
        /// </summary>
        /// <summary>
        public TUserPermissionRelation_Entity GetEntityByID(int id)
        {
            return dal.GetEntityByID(id);
        }
    }
}
